package com.zheng.mall.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 状态标记校验器
 * @author zheng
 */
public class FlagValidate implements ConstraintValidator<FlagValidator, Integer> {
    private String[] value;

    @Override
    public void initialize(FlagValidator flagValidator) {
        this.value = flagValidator.value();
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        boolean isValid = false;
        if (value == null){
            //状态为空时使用默认值
            return true;
        }
        for (int i = 0; i < value.length; i++) {
            if (value[i].equals(String.valueOf(value))) {
                isValid = true;
                break;
            }
        }
        return isValid;
    }
}
